package com.pulanit.pangu.admin.gen;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.TemplateType;
import com.baomidou.mybatisplus.generator.engine.VelocityTemplateEngine;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述
 *
 * @author: 天鸣
 * @date: 2023-03-21
 */
public class GenCode {
    private static final String prefix = "D:/bishe/online/pangu-admin-backend/pangu-admin-web/src/main/java/com/pulanit/pangu/admin/";

    private static final String apiPrefix = "D:/bishe/online/pangu-admin-backend/pangu-admin-system-api/src/main/java/com/pulanit/pangu/admin/business/api/";

    private static final String webPrefix = "D:/bishe/online/pangu-admin-frontend/src/";

    public static void main(String[] args) {
        Map<String, Object> customMap = new HashMap<>(16);
        Map<String, String> customFile = new HashMap<>(16);
        //自定义文件模板
        customFile.put(GenConstant.PAGE, "/vm/ssm/pageIn.java.vm");
        customFile.put(GenConstant.API, "/vm/vue2/api.js.vm");
        customFile.put(GenConstant.ADD, "/vm/vue2/add.vue.vm");
        customFile.put(GenConstant.INDEX, "/vm/vue2/index.vue.vm");

        Map<OutputFile, String> outputFileStringMap = new HashMap<>(10);
        outputFileStringMap.put(OutputFile.controller, prefix + "web/controller/business");
        outputFileStringMap.put(OutputFile.serviceImpl, prefix + "business/service");
        outputFileStringMap.put(OutputFile.service, apiPrefix + "service");
        outputFileStringMap.put(OutputFile.entity, apiPrefix + "entity");
        outputFileStringMap.put(OutputFile.mapper, prefix + "business/dao/mapper");
        String url = "jdbc:mysql://127.0.0.1:3306/bs_online?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
        FastAutoGenerator.create(url, "root", "123456")
                .globalConfig(builder -> {
                    builder.author("天鸣"); // 设置作者

                })
                .packageConfig(builder -> {
                    builder.parent("com.pulanit.pangu.admin") // 设置父包名
                            .controller("web.controller.business")
                            .entity("business.api.entity")
                            .service("business.api.service")
                            .mapper("business.dao.mapper")
                            .serviceImpl("business.service")
                            .pathInfo(outputFileStringMap);

                })
                //策略配置
                .strategyConfig(builder -> {
                    builder.addInclude("article_expert") // 设置需要生成的表名
                            .addFieldPrefix()
                            .entityBuilder()
                            .idType(IdType.AUTO)
                            .enableTableFieldAnnotation()
                            .enableLombok();
                })
                .templateConfig(builder -> builder.disable(TemplateType.CONTROLLER)
                        .controller("/vm/ssm/controller.java.vm"))
                .injectionConfig(builder -> builder.customMap(customMap).customFile(customFile))
                .templateEngine(new BrowserVelocityTemplateEngine(apiPrefix, webPrefix))
//                .templateEngine(new VelocityTemplateEngine())
                .execute();
    }

}
